{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pandas import Series, DataFrame\n",
    "import matplotlib as mpl\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def desc(data):\n",
    "    d = data.describe()\n",
    "    var = d.loc['std'] ** 2\n",
    "    iqr = d.loc['75%'] - d.loc['25%']\n",
    "    upper = d.loc['75%'] + 1.5 * iqr\n",
    "    lower = d.loc['25%'] - 1.5 * iqr\n",
    "    index = list(d.index)\n",
    "    index.insert(2, 'var')\n",
    "    index.extend(['iqr', 'upper', 'lower', 'outlier'])\n",
    "    r = d.reindex(index)\n",
    "    r.loc['var'] = var\n",
    "    r.loc['iqr'] = iqr\n",
    "    r.loc['upper'] = upper\n",
    "    r.loc['lower'] = lower\n",
    "    r.loc['outlier'] = (data > r.loc['upper']).sum() + (data < r.loc['lower']).sum()\n",
    "    return r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>10000.000000</td>\n",
       "      <td>10000.000000</td>\n",
       "      <td>10000.000000</td>\n",
       "      <td>10000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>-0.016771</td>\n",
       "      <td>0.005466</td>\n",
       "      <td>-0.013463</td>\n",
       "      <td>-0.006886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.989480</td>\n",
       "      <td>0.992725</td>\n",
       "      <td>0.995766</td>\n",
       "      <td>0.998081</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-3.693581</td>\n",
       "      <td>-3.854872</td>\n",
       "      <td>-3.625844</td>\n",
       "      <td>-3.983522</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>-0.687374</td>\n",
       "      <td>-0.654952</td>\n",
       "      <td>-0.686207</td>\n",
       "      <td>-0.656906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>-0.011495</td>\n",
       "      <td>0.003015</td>\n",
       "      <td>-0.009416</td>\n",
       "      <td>0.007462</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.657705</td>\n",
       "      <td>0.658911</td>\n",
       "      <td>0.656834</td>\n",
       "      <td>0.659247</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>3.413169</td>\n",
       "      <td>3.866579</td>\n",
       "      <td>3.931625</td>\n",
       "      <td>3.663877</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  A             B             C             D\n",
       "count  10000.000000  10000.000000  10000.000000  10000.000000\n",
       "mean      -0.016771      0.005466     -0.013463     -0.006886\n",
       "std        0.989480      0.992725      0.995766      0.998081\n",
       "min       -3.693581     -3.854872     -3.625844     -3.983522\n",
       "25%       -0.687374     -0.654952     -0.686207     -0.656906\n",
       "50%       -0.011495      0.003015     -0.009416      0.007462\n",
       "75%        0.657705      0.658911      0.656834      0.659247\n",
       "max        3.413169      3.866579      3.931625      3.663877"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = DataFrame(np.random.randn(10000,4), columns=list('ABCD'))\n",
    "d = df.describe()\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>10000.000000</td>\n",
       "      <td>10000.000000</td>\n",
       "      <td>10000.000000</td>\n",
       "      <td>10000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>-0.016771</td>\n",
       "      <td>0.005466</td>\n",
       "      <td>-0.013463</td>\n",
       "      <td>-0.006886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>var</th>\n",
       "      <td>0.979070</td>\n",
       "      <td>0.985503</td>\n",
       "      <td>0.991549</td>\n",
       "      <td>0.996165</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.989480</td>\n",
       "      <td>0.992725</td>\n",
       "      <td>0.995766</td>\n",
       "      <td>0.998081</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-3.693581</td>\n",
       "      <td>-3.854872</td>\n",
       "      <td>-3.625844</td>\n",
       "      <td>-3.983522</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>-0.687374</td>\n",
       "      <td>-0.654952</td>\n",
       "      <td>-0.686207</td>\n",
       "      <td>-0.656906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>-0.011495</td>\n",
       "      <td>0.003015</td>\n",
       "      <td>-0.009416</td>\n",
       "      <td>0.007462</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.657705</td>\n",
       "      <td>0.658911</td>\n",
       "      <td>0.656834</td>\n",
       "      <td>0.659247</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>3.413169</td>\n",
       "      <td>3.866579</td>\n",
       "      <td>3.931625</td>\n",
       "      <td>3.663877</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>iqr</th>\n",
       "      <td>1.345079</td>\n",
       "      <td>1.313862</td>\n",
       "      <td>1.343042</td>\n",
       "      <td>1.316153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>upper</th>\n",
       "      <td>2.675323</td>\n",
       "      <td>2.629704</td>\n",
       "      <td>2.671397</td>\n",
       "      <td>2.633476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>lower</th>\n",
       "      <td>-2.704992</td>\n",
       "      <td>-2.625745</td>\n",
       "      <td>-2.700770</td>\n",
       "      <td>-2.631135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>outlier</th>\n",
       "      <td>81.000000</td>\n",
       "      <td>88.000000</td>\n",
       "      <td>77.000000</td>\n",
       "      <td>98.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    A             B             C             D\n",
       "count    10000.000000  10000.000000  10000.000000  10000.000000\n",
       "mean        -0.016771      0.005466     -0.013463     -0.006886\n",
       "var          0.979070      0.985503      0.991549      0.996165\n",
       "std          0.989480      0.992725      0.995766      0.998081\n",
       "min         -3.693581     -3.854872     -3.625844     -3.983522\n",
       "25%         -0.687374     -0.654952     -0.686207     -0.656906\n",
       "50%         -0.011495      0.003015     -0.009416      0.007462\n",
       "75%          0.657705      0.658911      0.656834      0.659247\n",
       "max          3.413169      3.866579      3.931625      3.663877\n",
       "iqr          1.345079      1.313862      1.343042      1.316153\n",
       "upper        2.675323      2.629704      2.671397      2.633476\n",
       "lower       -2.704992     -2.625745     -2.700770     -2.631135\n",
       "outlier     81.000000     88.000000     77.000000     98.000000"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "desc(df)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
